package com.smarthome.core.message.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShSmsRecordService;
import com.smarthome.base.service.ShSmsTempletService;
import com.smarthome.core.message.MessageRecordService;
import com.smarthome.domain.bean.ShSmsRecord;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.rpc.SmsService;

@Service("messageRecordService")
public class MessageRecordServiceImpl implements MessageRecordService {

	@Resource(name="shSmsRecordService")
	private ShSmsRecordService recordService;

	@Resource(name = "smsService")
	private SmsService smsService;

	@Resource(name = "shSmsTempletService")
	private ShSmsTempletService templetService;

	@Override
	public DataGrid dataGrid(PageHelper page, ShSmsRecord record) {
		return recordService.queryShSmsRecords(page, record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.smarthome.core.messagetemplate.MessageRecordService#saveFall(com.
	 * smarthome.domain.bean.ShSmsRecord[])
	 */
	@Override
	public void saveFall(ShSmsRecord... records) {
		if(null == records) return ;
		for(ShSmsRecord record : records){
			if(null == record.getId())  continue;
			
			ShSmsRecord queryRecord =	recordService.selectEntryById(record.getId());
			if(null == queryRecord) continue;
			queryRecord.setErrorDate(new Date());
			queryRecord.setErrorMsg(record.getErrorMsg());
			queryRecord.setStatus(2);
			recordService.updateById(queryRecord);
		}

	}

	@Override
	public void complete(String... urid) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.smarthome.core.messagetemplate.MessageRecordService#fall(java.lang
	 * .String[])
	 */
	@Override
	public void fall(String... urid) {

	}

	/* (non-Javadoc)
	 * @see com.smarthome.core.message.MessageRecordService#queryRecord(com.smarthome.domain.bean.ShSmsRecord)
	 */
	@Override
	public List<ShSmsRecord> queryRecord(ShSmsRecord record) {
		return recordService.selectEntryList(record);
	}

	/* (non-Javadoc)
	 * @see com.smarthome.core.message.MessageRecordService#updateStatus(java.lang.Long, int)
	 */
	@Override
	public void updateStatus(Long id, int status) {
		ShSmsRecord record = 	recordService.selectEntryById(id);
		if(null == record) return ;
		record.setStatus(status);
		recordService.updateById(record);
	}
}
